package com.example.yichuangyun.mvvm.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.DataBindingHolder;
import com.example.yichuangyun.R;
import com.example.yichuangyun.databinding.ItemOrderDetailsServiceBinding;
import com.example.yichuangyun.model.order.ServiceRecordModel;

public class OrderServiceAdapter extends BaseQuickAdapter<ServiceRecordModel.ServiceModel, DataBindingHolder<ItemOrderDetailsServiceBinding>> {

    private final Context context;

    public OrderServiceAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void onBindViewHolder(@NonNull DataBindingHolder<ItemOrderDetailsServiceBinding> itemOrderTailsServiceBindingDataBindingHolder, int i, @Nullable ServiceRecordModel.ServiceModel serviceModel) {
        ItemOrderDetailsServiceBinding binding = itemOrderTailsServiceBindingDataBindingHolder.getBinding();
        binding.setServiceModel(serviceModel);
        binding.line.setVisibility(i == getItemCount() - 1 ? View.GONE : View.VISIBLE);
        if (serviceModel != null) {
            // 状态 0待办、1在办、2暂停、3办结、4终止
            switch (serviceModel.getStatus()) {
                case 2:
                    binding.tvServiceStatus.setTextColor(context.getColor(R.color.color_FFAF29));
                    binding.tvServiceStatus.setBackgroundResource(R.drawable.shape_bg_ffaf29);
                    break;
                case 3:
                    binding.tvServiceStatus.setTextColor(context.getColor(R.color.color_8D9AA9));
                    binding.tvServiceStatus.setBackgroundResource(R.drawable.shape_time_bg_def);
                    break;
                case 4:
                    binding.tvServiceStatus.setTextColor(context.getColor(R.color.color_BBC2CB));
                    binding.tvServiceStatus.setBackgroundResource(R.drawable.shape_bg_bbc2cb);
                    break;
                default:
                    binding.tvServiceStatus.setTextColor(context.getColor(R.color.color_426FFF));
                    binding.tvServiceStatus.setBackgroundResource(R.drawable.shape_time_bg_sel);
                    break;
            }
            binding.tvMoneyConfirmStatus.setBackgroundResource(serviceModel.getMoneyConfirmStatus() > 1 ? R.drawable.shape_time_bg_sel : R.drawable.shape_time_bg_def);
            binding.tvMoneyConfirmStatus.setTextColor(serviceModel.getMoneyConfirmStatus() > 1 ? context.getColor(R.color.color_426FFF) : context.getColor(R.color.color_8D9AA9));
        }
    }

    @NonNull
    @Override
    protected DataBindingHolder<ItemOrderDetailsServiceBinding> onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        return new DataBindingHolder<>(R.layout.item_order_details_service, viewGroup);
    }
}
